use Test;

### Entity Test:
### ==============
## Test that the tested object is a correctly created entity of the specified type

package EntityTest;
## Keys for accessing the container:
#-----------------------------------
# TESTED_OBJ: Actual created object under test
# TESTED_OBJ_ENTITY_TYPE: What the "type" method of the TESTED_OBJ should return

@ISA = qw/Test/;

our @DEPENDS_ON = qw/creation/;

sub init{
    my $self = shift;
}

sub setup{
    my $self = shift;
}

sub run{
    my $self = shift;

    my $obj = $self->component("TESTED_OBJ");
    my $expected_type = $self->component("ENTITY_EXPECTED_TYPE");


    $self->log("Retrieving object: ".$obj);
    my $entity_type = $obj->type;
    $self->log("Retrieving type: ".$entity_type."; expected ".$expected_type);
    $self->assertEq($entity_type, $expected_type, "ENTITY_TYPE_CHECK");

    $self->log("Testing Attributes");
    my ($name, $val) = ("TestAttribute", "TestAttributeValue");
    my $attr = $obj->attr($name, $val);    
    $self->assertEq($val, $attr, "ATTRIBUTE_RETURNED_ON_SET");
    $attr = $obj->attr($name);
    $self->assertEq($val, $attr, "ATTRIBUTE_RETURNED_ON_REQUEST");


    # Pic should be the same as the one set in the container
    my $expectedPic = $self->component("ENTITY_EXPECTED_PIC");
    $self->log("Retrieving Pic: ".$obj->pic."; expected: ".$expectedPic);
    $self->assertEq($obj->pic, $expectedPic, "PIC");

    my $contents = $obj->contents;
    $self->log("Retrieving Contents: ".$contents);
    $self->log("Testing if Contents is of the correct type: ".(ref $contents));
    $self->assertEq((ref $contents), "EntityBag", "CONTENTS_REF_TYPE");
    
    my $contents2 = $obj->contents;
    $self->log("Retrieving contents again: ".$contents2."; should be ".$contents);
    $self->assertEq($contents, $obj->contents, "CONTENTS_IDENTITY");


    $self->log("Testing Position");
    my $pos = $obj->pos;
    $self->assertEq($pos, $obj->pos, "POS_IDENTITY");

}

sub teardown{
    my $self = shift;
}

1;
